<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%"
      :default-sort="{ prop: 'date', order: 'descending' }"
    >
      <el-table-column prop="type" label="类型" sortable width="100">
        <template slot-scope="scope">
          {{ questiontype(scope.row.type) }}
        </template>
      </el-table-column>
      <el-table-column prop="subject" label="科目" sortable width="100">
        <template slot-scope="scope">
          {{ subjecttype(scope.row.type) }}
        </template>
      </el-table-column>
      <el-table-column
        prop="context"
        label="问题描述"
        sortable
        width="200"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="upload_time"
        label="上传时间"
        sortable
        width="112"
        show-overflow-tooltip
        ><template slot-scope="scope">
          {{ new Date(scope.row.upload_time).toLocaleString() }}
        </template>
      </el-table-column>
   

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="answerEdit(scope.row)"
            >回复</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import axios from "axios";
import commons from "../../assets/commons";
export default {
  data() {
    return {
      tableData: [], //总的集合
      dialogVisible: false,
      question: "",
      answer: "",
      type_question: ["选择题", "填空题", "解答题", "作文题"],
      type_subject: [
        "语文",
        "数学",
        "英语",
        "政治",
        "历史",
        "生物",
        "物理",
        "化学",
        "生物",
      ],
      msg: "",
    };
  },
  methods: {
     findAllQuestion() {
      axios
        .get(
          "http://localhost:8080/findQuestion_ask",
          //完成作业ID
          {
            params: {
              userid: this.$store.state.userid,
            },
          }
        )
        .then((resp) => {
         // console.log(resp.data);
          this.tableData = resp.data;
        });
    },
    answerEdit(row) {
      console.log(row);
        this.$prompt(row.context, '问题', {
          confirmButtonText: '回复',
          cancelButtonText: '返回',
        }).then(({ value }) => {
        row.answer=value
         axios
        .get(
          "http://localhost:8080/AnswerQuestion",
       
          {
            params: {
              qustionAnswer: row.answer,
               id: row.id,
            },
          }
        )
        .then((resp) => {
         // console.log(resp.data);
        this.msg=resp.data
      
       if(this.msg==200){
          this.$message({
            type: 'success',
            message: '回复成功'
          });
        
           this.findAllQuestion()
        }
        else{
          this.$message({
            type: 'info',
            message: '回复失败'
          });
        }
        });
       
         
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消回复'
          });       
        });
    },
   
    questiontype(type) {
      return this.type_question[type - 1];
    },
    subjecttype(subject) {
      return this.type_subject[subject - 1];
    }
  },
  //生命周期函数,在页面创建成功时回调
  mounted() {
    this.findAllQuestion();
  },
};
</script>
<style scoped></style>
